<?php
/**
 *
 *
 * @author Zeon <scplay@gmail.com>
 * @date 2019/5/31 9:28
 * @copyright PanxSoft Inc.
 */

namespace App\Http\Requests\App\V1\UserDevicePreset;

use App\Http\Requests\ApiRequest;

/**
 * Trait UserDevicePresetRule
 *
 * @package App\Http\Requests\App\V1\UserDevicePreset
 */
trait UserDevicePresetRule
{
    /**
     * @return array
     */
    public function presetJSON(): ?array
    {
        /** @var ApiRequest $this */
        return json_decode($this->get('preset'), $as_array = true);
    }

    public function dataRules(): array
    {
        return $rule = [
            'name'              => ['required', 'string'],
            'preset'            => ['required', 'json'],
            'luminance'         => 'nullable|int',
            'color_temperature' => 'nullable|int',
            'is_default'        => ['boolean'],
        ];
    }
}